package pcgen.android.app;

import android.os.Parcel;
import android.os.Parcelable;

import pcgen.android.Logger;

public abstract class ParcelableEx implements Parcelable
{
	public ParcelableEx()
	{
	}
	
	public ParcelableEx(Parcel in)
	{
		readFromParcel(in);
	}
	
	public int describeContents()
	{
		return 0;
	}
	
	public void readFromParcel(Parcel in)
	{
		try
		{
			readFromParcelTransform(in);
		}
		catch (Throwable tr)
		{
			Logger.e(TAG, "readFromParcel", tr);
		}
	}
	
	public void writeToParcel(Parcel dest, int flags) 
	{
		try
		{
			writeToParcelTransform(dest, flags);
		}
		catch (Throwable tr)
		{
			Logger.e(TAG, "writeToParcel", tr);
		}
	}
	
	protected abstract void readFromParcelTransform(Parcel in)
		throws Throwable;
	
	protected abstract void writeToParcelTransform(Parcel dest, int flags)
			throws Throwable;
    
    private static final String TAG = ParcelableEx.class.getSimpleName();
}
